MAX = 10 
mat = [i for i in range(MAX)]
use = [0 for i in range(MAX)]
num = [0 for i in range(MAX)]
cnt = 0
def solve(l):
    global MAX
    global mat
    global use
    global num
    global cnt
    if cnt > 1000000:
        return
    if l >= MAX:
        cnt += 1
        if cnt == 1000000:
            print num
        return 
        
    for i in range(0, MAX):
        if not use[i]:
            num[l] = mat[i]
            use[i] = 1 
            solve(l+1) 
            use[i] = 0
 
if __name__ == "__main__":
    solve(0)

                                     

    
    
